package com.ocom.webapi.controller;

import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.request.payconfig.IotDeviceListRequest;
import com.ocom.common.request.payconfig.NewIotDeviceRequest;
import com.ocom.common.request.payconfig.RemoveIotDeviceRequest;
import com.ocom.common.request.payconfig.UpdateIotDeviceRequest;
import com.ocom.common.resp.Result;
import com.ocom.security.authentication.YoCiUser;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.feign.PayConfigClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IotDeviceController {
    @Autowired
    private PayConfigClientService payConfigClientService;

    @PostMapping(WebApiServiceUrl.URL_IotDeviceOnShow)
    public Result OnShow(@RequestBody IotDeviceListRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setMerchId(yoCiUser.getMerchId());
        request.setComId(yoCiUser.getComId());
        return this.payConfigClientService.iotDeviceList(request);
    }

    @PostMapping(WebApiServiceUrl.URL_IotDeviceAdd)
    public Result Add(@RequestBody NewIotDeviceRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setMerchId(yoCiUser.getMerchId());
        request.setComId(yoCiUser.getComId());
        return this.payConfigClientService.newIotDevice(request);
    }
    @PostMapping(WebApiServiceUrl.URL_IotDeviceModify)
    public Result Modify(@RequestBody UpdateIotDeviceRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setMerchId(yoCiUser.getMerchId());
        request.setComId(yoCiUser.getComId());
        return this.payConfigClientService.updateIotDevice(request);
    }
    @PostMapping(WebApiServiceUrl.URL_IotDeviceDelete)
    public Result Delete(@RequestBody RemoveIotDeviceRequest request){
        YoCiUser yoCiUser = SecurityUtils.getYoCiUser();
        request.setMerchId(yoCiUser.getMerchId());
        request.setComId(yoCiUser.getComId());
        return this.payConfigClientService.removeIotDevice(request);
    }

}
